package com.atguigu.gmall.list.rpc;

import com.atguigu.gmall.common.result.Result;
import com.atguigu.gmall.list.service.SearchService;
import com.atguigu.gmall.model.list.Goods;
import com.atguigu.gmall.model.list.SearchParam;
import com.atguigu.gmall.model.vo.GoodsSearchResultVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * @Author 卡尼奶
 * @Date 2022/5/28 14:21
 * @Version 1.0
 */
@RestController
@RequestMapping("/rpc/product")
public class SearchController {

    @Autowired
    private SearchService searchService;

    @PostMapping("/list/save")
    public Result searchProduct(@RequestBody Goods goods){
        searchService.saveSearch(goods);
        return Result.ok();
    }

    @DeleteMapping("/list/delete/{id}")
    public Result deleteSearchProduct(@PathVariable("id")Long id){
        searchService.deleteSearchProduct(id);
        return Result.ok();
    }

    /**
     * 检索商品
     * @param param
     * @return
     */
    @PostMapping("/goods/search")
    public Result<GoodsSearchResultVo> searchGoods(@RequestBody SearchParam param){
        GoodsSearchResultVo goodsSearchResultVo = searchService.searchGoods(param);
        return Result.ok(goodsSearchResultVo);
    }

    /**
     * 更新商品热度
     * @param skuId
     * @param score
     * @return
     */
    @GetMapping("/goods/incrHotScore/{skuId}")
    public Result incrHotScore(@PathVariable("skuId")Long skuId,
                               @RequestParam("score")Long score){
        searchService.incrHotScore(skuId,score);
        return Result.ok();
    }
}
